<template>
  <div class="bg-box">
    <!-- 图片 -->
    <van-swipe :autoplay="3000">
      <van-swipe-item v-for="(image, index) in houseInfo.houseImg" :key="index">
        <img v-lazy="image" />
      </van-swipe-item>
    </van-swipe>
    <!-- 详情 -->
    <van-cell-group class="detail-title">
      <van-cell :title="houseInfo.title" value="内容">
        <template #default>
          <van-tag
            :color="color[Math.floor(Math.random() * color.length)]"
            :text-color="textColor[Math.floor(Math.random() * color.length)]"
            v-for="(item, index) in houseInfo.tags"
            :key="index"
            >{{ item }}
          </van-tag>
        </template>
      </van-cell>
      <van-cell value="内容" class="cell-main">
        <div>
          <span>{{ houseInfo.price }}/月</span><span>租金</span>
        </div>
        <div>
          <span>{{ houseInfo.roomType }}</span
          ><span>房型</span>
        </div>
        <div>
          <span>{{ houseInfo.size }}</span
          ><span>面积</span>
        </div>
      </van-cell>
      <van-cell value="内容" class="cell-footer">
        <div>
          <div><span>装修：</span><span>精装</span></div>
          <div>
            <span>楼层：</span><span>{{ houseInfo.floor }}</span>
          </div>
        </div>
        <div>
          <div>
            <span>朝向：</span
            ><span v-for="(item, index) in houseInfo.oriented" :key="index">{{
              item
            }}</span>
          </div>
          <div><span>类型：</span><span>普通住宅</span></div>
        </div>
      </van-cell>
    </van-cell-group>
    <!-- 地图位置 -->
    <van-cell-group class="detail-map">
      <van-cell>
        <template #title> 小区：{{ houseInfo.community }} </template>
        <template #label>
          <div id="container"></div>
        </template>
      </van-cell>
    </van-cell-group>
    <!-- 房屋配套 -->
    <van-cell-group class="detail-furniture">
      <van-cell title="房屋配套" />
      <van-cell value="暂无数据" />
    </van-cell-group>
    <!-- 房源概况 -->
    <van-cell-group class="detail-desc">
      <van-cell title="房源概况" />
      <van-cell value="">
        <div>
          <div class="img">
            <div class="img-box">
              <img src="http://124.223.73.204:8080/img/avatar.png" alt="" />
            </div>
            <div>
              <span>王女士</span>
              <span><van-icon name="passed" size="15" />已认证房主</span>
            </div>
          </div>
          <div>
            <van-button plain type="primary" size="small">发消息</van-button>
          </div>
        </div>
        <div>{{ houseInfo.description || "暂无房屋描述"}}</div>
      </van-cell>
    </van-cell-group>
    <!-- 猜你喜欢 -->
    <van-cell-group>
      <van-cell title="猜你喜欢"></van-cell>
      <van-card
      class="card-desc"
        price="4500/月"
        title="安贞西里 3室1厅"
        desc="72.32m²/南 北/低楼层"
        thumb="http://124.223.73.204:8080/img/message/1.png"
      >
        <template #tags>
          <van-tag color="#e1f5f8" text-color="#39becd">近地铁</van-tag>
        </template>
      </van-card>
      <van-card
        price="7200/月"
        title="天居园 2室1厅"
        desc="83㎡/南/高楼层"
        thumb="http://124.223.73.204:8080/img/message/2.png"
      >
        <template #tags>
          <van-tag color="#e1f5f8" text-color="#39becd">随时看房</van-tag>
        </template>
      </van-card>
      <van-card
        price="4300/月"
        title="角门甲4号院 1室1厅"
        desc="52㎡/西南/低楼层"
        thumb="http://124.223.73.204:8080/img/message/3.png"
      >
        <template #tags>
          <van-tag color="#e1f5f8" text-color="#39becd">集中供暖</van-tag>
        </template>
      </van-card>
    </van-cell-group>
    <div class="footer">
      <div><van-icon name="star-o" />收藏</div>
      <div>在线咨询</div>
      <div>电话预约</div>
    </div>
    <div style="height: 50px;"></div>
  </div>
</template>

<script>
import { getSpecificHouse } from '@/api/house'
export default {
  name: 'DetailsPage',
  props: {},
  data () {
    return {
      houseInfo: {},
      color: ['#e1f5f8', '#e1f5ed', '#e6f2ff'],
      textColor: ['#39becd', '#58ca9a', '#5aabfd']
    }
  },
  watch: {},
  computed: {},
  created () {},
  mounted () {
    this.getSpecificHouse()
  },
  methods: {
    async getSpecificHouse () {
      const id = this.$route.params.id
      const {
        data: { body }
      } = await getSpecificHouse(id)
      console.log(body)
      this.houseInfo = body
      this.houseInfo.houseImg = body.houseImg.map((item) => {
        item = 'http://124.223.73.204:8080' + item
        return item
      })
      // 小区地图
      const { BMapGL } = window
      const map = new BMapGL.Map('container')
      map.centerAndZoom(
        new BMapGL.Point(body.coord.longitude, body.coord.latitude),
        17
      )
      const opts = {
        position: new BMapGL.Point(body.coord.longitude, body.coord.latitude), // 指定文本标注所在的地理位置
        offset: new BMapGL.Size(10, -50) // 设置文本偏移量
      }
      // 创建文本标注对象
      const label = new BMapGL.Label(body.community, opts)
      // 自定义文本标注样式
      label.setStyle({
        color: '#fff',
        borderRadius: '5px',
        borderColor: '#ff0000',
        backgroundColor: '#ee5d5b',
        padding: '10px',
        fontSize: '12px',
        height: '10px',
        lineHeight: '10px',
        fontFamily: '微软雅黑'
      })
      map.addOverlay(label)
    }
  }
}
</script>
<style lang="less" scoped>
.bg-box {
  background-color: #f6f5f6;
  height: 1500px;
}
.van-swipe {
  background-color: #f7f7f7;
  height: 252px;
  width: 100%;
}
img {
  width: 100%;
  height: 100%;
}
//
.van-cell-group {
  margin-top: 20px;
}
// 详情

.detail-title {
  margin-top: 0;
  .van-cell {
    flex-direction: column;
    width: 100%;
    height: 90px;
  }
  .van-cell::after {
    border-bottom: 1px solid #cecece !important;
  }
  .van-cell__title {
    font-size: 16px;
  }
  .van-cell__value {
    text-align: left;
  }
  .cell-main {
    .van-cell__value {
      display: flex;
      justify-content: space-evenly;
      div {
        display: flex;
        flex-direction: column;
        justify-content: center;
        color: #fa5741;
        font-size: 18px;
        font-weight: bold;
        text-align: center;
        span:last-child {
          color: #999999;
          font-weight: normal;
          font-size: 14px;
        }
      }
    }
  }
  .cell-footer .van-cell__value {
    display: flex;
    div {
      flex: 1;
      span:first-child {
        color: #999999;
      }
      span:last-child {
        margin-left: 5px;
      }
    }
  }
}
// 地图详情
.detail-map {
  #container {
    width: 100%;
    height: 220px;
  }
}
// 房屋配置
.detail-furniture {
  margin: 0px;
  .van-cell__title {
    font-size: 16px;
    font-weight: bold;
  }
}
// 房源概况
.detail-desc {
  .van-cell__title {
    font-size: 16px;
    font-weight: bold;
  }
  .van-cell__value > div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .img {
      display: flex;
      margin-bottom: 10px;
      // justify-content: space-around;
      // align-items: center;
      .img-box {
        width: 52px !important;
        height: 52px !important;
        background-color: pink;
        margin-right: 10px;
        border-radius: 50%;
        img {
          width: 100%;
          height: 100%;
        }
      }
      span {
        display: block;
        width: 81px;
      }
      span:last-child {
        color: #fa5741;
        font-size: 12px;
      }
    }
  }
}
// 猜你喜欢
.van-cell__title {
    font-size: 16px;
    font-weight: bold;
  }
.van-card__thumb {
  flex: 1;
}
/deep/.van-card__thumb img {
  border-radius: 0;
  width: 110px;
  height: 80px;
}
.van-card__content {
  flex: 2;
  >div>div{
    font-size: 16px;
    font-weight: bold !important;
  }
}
.van-card__price {
  color: rgb(255, 60, 0) !important;
}

.van-multi-ellipsis--l2 {
  -webkit-line-clamp: 1;
}
// 底部
.footer {
  position: fixed;
  bottom: 0;
  width: 100%;
  height: 50px;
  border: 1px solid #cbcbcb;
  display: flex;
  text-align: center;
  line-height: 50px;
  background-color: #fff;
  color: #999999;
  font-size: 18px;
  > div {
    flex: 1;
    height: 50px;
  }
  > div:nth-child(2) {
    border-left: 1px solid #cbcbcb;
    border-right: 1px solid #cbcbcb;
  }
  > div:last-child {
    background-color: #21b97a;
    color: #ffffff;
  }
}
</style>
